<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Tips for writing native applications</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/writing-native-applications-tips" />
  <meta property="og:title" content="Quarkus - Tips for writing native applications" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/writing-native-applications-tips">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Tips for writing native applications</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#supporting-native-in-your-application">Supporting native in your application</a>
<ul class="sectlevel2">
<li><a href="#including-resources">Including resources</a></li>
<li><a href="#registering-for-reflection">Registering for reflection</a></li>
<li><a href="#delaying-class-initialization">Delaying class initialization</a></li>
<li><a href="#managing-proxy-classes">Managing Proxy Classes</a></li>
</ul>
</li>
<li><a href="#native-in-extension">Supporting native in a Quarkus extension</a>
<ul class="sectlevel2">
<li><a href="#register-reflection">Register reflection</a></li>
<li><a href="#alternative-with-registerforreflection">Alternative with @RegisterForReflection</a></li>
<li><a href="#including-resources-2">Including resources</a></li>
</ul>
</li>
<li><a href="#delay-class-initialization">Delay class initialization</a>
<ul class="sectlevel2">
<li><a href="#managing-proxy-classes-2">Managing Proxy Classes</a></li>
<li><a href="#logging-with-native-image">Logging with Native Image</a></li>
</ul>
</li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>This guide contains various tips and tricks for getting around problems that might arise when attempting to run Java applications as native executables.</p>
</div>
<div class="paragraph">
<p>Note that we differentiate two contexts where the solution applied might be different:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>in the context of an application, you will rely on configuring the <code>native-image</code> configuration by tweaking your <code>pom.xml</code>;</p>
</li>
<li>
<p>in the context of an extension, Quarkus offers a lot of infrastructure to simplify all of this.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Please refer to the appropriate section depending on your context.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="supporting-native-in-your-application"><a class="anchor" href="#supporting-native-in-your-application"></a>Supporting native in your application</h2>
<div class="sectionbody">
<div class="paragraph">
<p>GraalVM imposes a number of constraints and making your application a native executable might require a few tweaks.</p>
</div>
<div class="sect2">
<h3 id="including-resources"><a class="anchor" href="#including-resources"></a>Including resources</h3>
<div class="paragraph">
<p>By default, when building a native executable, GraalVM will not include any of the resources that are on the classpath into the native executable it creates.
Resources that are meant to be part of the native executable need to be configured explicitly.</p>
</div>
<div class="paragraph">
<p>Quarkus automatically includes the resources present in <code>META-INF/resources</code> (the web resources) but, outside of this directory, you are on your own.</p>
</div>
<div class="paragraph">
<p>To include more resources in the native executable, create a <code>resources-config.json</code> (the most common location is within <code>src/main/resources</code>) JSON file defining which resources should be included:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="json" class="language-json hljs">{
  "resources": [
    {
      "pattern": ".*\\.xml$"
    },
    {
      "pattern": ".*\\.json$"
    }
  ]
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The patterns are valid Java regexps.
Here we include all the XML files and JSON files into the native executable.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>You can find more information about this topic in <a href="https://github.com/oracle/graal/blob/master/substratevm/RESOURCES.md">the GraalVM documentation</a>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The final order of business is to make the configuration file known to the <code>native-image</code> executable by adding the proper configuration to <code>application.properties</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.native.additional-build-args =-H:ResourceConfigurationFiles=resources-config.json</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the previous snippet we were able to simply use <code>resources-config.json</code> instead of specifying the entire path of the file simply because it was added to <code>src/main/resources</code>.
If the file had been added to another directory, the proper file path would have had to be specified manually.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Multiple options may be separated by a comma. For example, one could use:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.native.additional-build-args =\
    -H:ResourceConfigurationFiles=resources-config.json,\
    -H:ReflectionConfigurationFiles=reflection-config.json</code></pre>
</div>
</div>
<div class="paragraph">
<p>in order to ensure that various resources are included and additional reflection is registered.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>If for some reason adding the aforementioned configuration to <code>application.properties</code> is not desirable, it is possible to configure the build tool to effectively perform the same operation.</p>
</div>
<div class="paragraph">
<p>When using Maven, we could use the following configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;profiles&gt;
    &lt;profile&gt;
        &lt;id&gt;native&lt;/id&gt;
        &lt;properties&gt;
            &lt;quarkus.package.type&gt;native&lt;/quarkus.package.type&gt;
            &lt;quarkus.native.additional-build-args&gt;-H:ResourceConfigurationFiles=resources-config.json&lt;/quarkus.native.additional-build-args&gt;
        &lt;/properties&gt;
    &lt;/profile&gt;
&lt;/profiles&gt;</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="registering-for-reflection"><a class="anchor" href="#registering-for-reflection"></a>Registering for reflection</h3>
<div class="paragraph">
<p>When building a native executable, GraalVM operates with a closed world assumption.
It analyzes the call tree and removes all the classes/methods/fields that are not used directly.</p>
</div>
<div class="paragraph">
<p>The elements used via reflection are not part of the call tree so they are dead code eliminated (if not called directly in other cases).
To include these elements in your native executable, you need to register them for reflection explicitly.</p>
</div>
<div class="paragraph">
<p>This is a very common case as JSON libraries typically use reflection to serialize the objects to JSON:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">    public class Person {
        private String first;
        private String last;

        public String getFirst() {
            return first;
        }

        public void setFirst(String first) {
            this.first = first;
        }

        public String getLast() {
            return last;
        }

        public void setValue(String last) {
            this.last = last;
        }
    }

    @Path("/person")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public class PersonResource {

        private final Jsonb jsonb;

        public PersonResource() {
            jsonb = JsonbBuilder.create(new JsonbConfig());
        }

        @GET
        public Response list() {
            return Response.ok(jsonb.fromJson("{\"first\":  \"foo\", \"last\":  \"bar\"}", Person.class)).build();
        }
    }</code></pre>
</div>
</div>
<div class="paragraph">
<p>If we were to use the code above, we would get an exception like the following when using the native executable:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">Exception handling request to /person: org.jboss.resteasy.spi.UnhandledException: javax.json.bind.JsonbException: Can't create instance of a class: class org.acme.jsonb.Person, No default constructor found</code></pre>
</div>
</div>
<div class="paragraph">
<p>or if you are using Jackson:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.acme.jsonb.Person and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)</code></pre>
</div>
</div>
<div class="paragraph">
<p>An even nastier possible outcome could be for no exception to be thrown, but instead the JSON result would be completely empty.</p>
</div>
<div class="paragraph">
<p>There are two different ways to fix this type of issues.</p>
</div>
<div class="sect3">
<h4 id="using-the-registerforreflection-annotation"><a class="anchor" href="#using-the-registerforreflection-annotation"></a>Using the @RegisterForReflection annotation</h4>
<div class="paragraph">
<p>The easiest way to register a class for reflection is to use the <code>@RegisterForReflection</code> annotation:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@RegisterForReflection
public class MyClass {
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="using-a-configuration-file"><a class="anchor" href="#using-a-configuration-file"></a>Using a configuration file</h4>
<div class="paragraph">
<p>Obviously, adding <code>@RegisterForReflection</code> is not possible if the class is in a third-party jar.</p>
</div>
<div class="paragraph">
<p>In this case, you can use a configuration file to register classes for reflection.</p>
</div>
<div class="paragraph">
<p>As an example, in order to register all methods of class <code>com.acme.MyClass</code> for reflection, we create <code>reflection-config.json</code> (the most common location is within <code>src/main/resources</code>)</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="json" class="language-json hljs">[
  {
    "name" : "com.acme.MyClass",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true
  }
]</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>For more details on the format of this file, please refer to <a href="https://github.com/oracle/graal/blob/master/substratevm/REFLECTION.md">the GraalVM documentation</a>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The final order of business is to make the configuration file known to the <code>native-image</code> executable by adding the proper configuration to <code>application.properties</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the previous snippet we were able to simply use <code>reflection-config.json</code> instead of specifying the entire path of the file simply because it was added to <code>src/main/resources</code>.
If the file had been added to another directory, the proper file path would have had to be specified manually.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Multiple options may be separated by a comma. For example, one could use:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">quarkus.native.additional-build-args =\
    -H:ResourceConfigurationFiles=resources-config.json,\
    -H:ReflectionConfigurationFiles=reflection-config.json</code></pre>
</div>
</div>
<div class="paragraph">
<p>in order to ensure that various resources are included and additional reflection is registered.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>If for some reason adding the aforementioned configuration to <code>application.properties</code> is not desirable, it is possible to configure the build tool to effectively perform the same operation.</p>
</div>
<div class="paragraph">
<p>When using Maven, we could use the following configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;profiles&gt;
    &lt;profile&gt;
        &lt;id&gt;native&lt;/id&gt;
        &lt;properties&gt;
            &lt;quarkus.package.type&gt;native&lt;/quarkus.package.type&gt;
            &lt;quarkus.native.additional-build-args&gt;-H:ReflectionConfigurationFiles=reflection-config.json&lt;/quarkus.native.additional-build-args&gt;
        &lt;/properties&gt;
    &lt;/profile&gt;
&lt;/profiles&gt;</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="delaying-class-initialization"><a class="anchor" href="#delaying-class-initialization"></a>Delaying class initialization</h3>
<div class="paragraph">
<p>By default, Quarkus initializes all classes at build time.</p>
</div>
<div class="paragraph">
<p>There are cases where the initialization of certain classes is done in a static block needs to be postponed to runtime.
Typically omitting such configuration would result in a runtime exception like the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.security.provider.NativePRNG
Trace: object java.security.SecureRandom
method com.amazonaws.services.s3.model.CryptoConfiguration.&lt;init&gt;(CryptoMode)
Call path from entry point to com.amazonaws.services.s3.model.CryptoConfiguration.&lt;init&gt;(CryptoMode):</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you need to delay the initialization of a class, you can use the <code>--initialize-at-run-time=&lt;package or class&gt;</code> configuration knob.</p>
</div>
<div class="paragraph">
<p>It should be added to the <code>native-image</code> configuration using an <code>&lt;additionalBuildArg&gt;</code> as shown in the examples above.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>You can find more information about all this in <a href="https://github.com/oracle/graal/blob/master/substratevm/CLASS-INITIALIZATION.md">the GraalVM documentation</a>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>When multiple classes or packages need to be specified via the <code>quarkus.native.additional-build-args</code> configuration property, the <code>,</code> symbol needs to be escaped.
An example of this is the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.native.additional-build-args=--initialize-at-run-time=com.example.SomeClass\\,org.acme.SomeOtherClass</code></pre>
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="managing-proxy-classes"><a class="anchor" href="#managing-proxy-classes"></a>Managing Proxy Classes</h3>
<div class="paragraph">
<p>While writing native application you&#8217;ll need to define proxy classes at image build time by specifying the list of interfaces that they implement.</p>
</div>
<div class="paragraph">
<p>In such a situation, the error you might encounter is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.apache.http.conn.HttpClientConnectionManager, interface org.apache.http.pool.ConnPoolControl, interface com.amazonaws.http.conn.Wrapped] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=&lt;comma-separated-config-files&gt; and -H:DynamicProxyConfigurationResources=&lt;comma-separated-config-resources&gt; options.</code></pre>
</div>
</div>
<div class="paragraph">
<p>Solving this issue requires adding the <code>-H:DynamicProxyConfigurationResources=&lt;comma-separated-config-resources&gt;</code> option and to provide a dynamic proxy configuration file.
You can find all the information about the format of this file in <a href="https://github.com/oracle/graal/blob/master/substratevm/DYNAMIC_PROXY.md#manual-configuration">the GraalVM documentation</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="native-in-extension"><a class="anchor" href="#native-in-extension"></a>Supporting native in a Quarkus extension</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Supporting native in a Quarkus extension is even easier as Quarkus provides a lot of tools to simplify all this.</p>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Everything described here will only work in the context of Quarkus extensions, it won&#8217;t work in an application.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="sect2">
<h3 id="register-reflection"><a class="anchor" href="#register-reflection"></a>Register reflection</h3>
<div class="paragraph">
<p>Quarkus makes registration of reflection in an extension a breeze by using <code>ReflectiveClassBuildItem</code>, thus eliminating the need for a JSON configuration file.</p>
</div>
<div class="paragraph">
<p>To register a class for reflection, one would need to create a Quarkus processor class and add a build step that registers reflection:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class SaxParserProcessor {

    @BuildStep
    ReflectiveClassBuildItem reflection() {
        // since we only need reflection to the constructor of the class, we can specify `false` for both the methods and the fields arguments.
        return new ReflectiveClassBuildItem(false, false, "com.sun.org.apache.xerces.internal.parsers.SAXParser");
    }

}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>More information about reflection in GraalVM can be found <a href="https://github.com/oracle/graal/blob/master/substratevm/REFLECTION.md">here</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="alternative-with-registerforreflection"><a class="anchor" href="#alternative-with-registerforreflection"></a>Alternative with @RegisterForReflection</h3>
<div class="paragraph">
<p>As for applications, you can also use the <code>@RegisterForReflection</code> annotation if the class is in your extension and not in a third-party jar.</p>
</div>
</div>
<div class="sect2">
<h3 id="including-resources-2"><a class="anchor" href="#including-resources-2"></a>Including resources</h3>
<div class="paragraph">
<p>In the context of an extension, Quarkus eliminates the need for a JSON configuration file by allowing extension authors to specify a <code>NativeImageResourceBuildItem</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class ResourcesProcessor {

    @BuildStep
    NativeImageResourceBuildItem nativeImageResourceBuildItem() {
        return new NativeImageResourceBuildItem("META-INF/extra.properties");
    }

}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>For more information about GraalVM resource handling in native executables please refer to <a href="https://github.com/oracle/graal/blob/master/substratevm/RESOURCES.md">the GraalVM documentation</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="delay-class-initialization"><a class="anchor" href="#delay-class-initialization"></a>Delay class initialization</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Quarkus simplifies things by allowing extensions authors to simply register a <code>RuntimeInitializedClassBuildItem</code>. A simple example of doing so could be:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class S3Processor {

    @BuildStep
    RuntimeInitializedClassBuildItem cryptoConfiguration() {
        return new RuntimeInitializedClassBuildItem(CryptoConfiguration.class.getCanonicalName());
    }

}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Using such a construct means that a <code>--initialize-at-run-time</code> option will automatically be added to the <code>native-image</code> command line.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>For more information about <code>--initialize-at-run-time</code>, please read <a href="https://github.com/oracle/graal/blob/master/substratevm/CLASS-INITIALIZATION.md">the GraalVM documentation</a>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="sect2">
<h3 id="managing-proxy-classes-2"><a class="anchor" href="#managing-proxy-classes-2"></a>Managing Proxy Classes</h3>
<div class="paragraph">
<p>Very similarly, Quarkus allows extensions authors to register a <code>NativeImageProxyDefinitionBuildItem</code>. An example of doing so is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class S3Processor {

    @BuildStep
    NativeImageProxyDefinitionBuildItem httpProxies() {
        return new NativeImageProxyDefinitionBuildItem("org.apache.http.conn.HttpClientConnectionManager",
                "org.apache.http.pool.ConnPoolControl", "com.amazonaws.http.conn.Wrapped");
    }

}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Using such a construct means that a <code>-H:DynamicProxyConfigurationResources</code> option will automatically be added to the <code>native-image</code> command line.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>For more information about Proxy Classes you can read <a href="https://github.com/oracle/graal/blob/master/substratevm/DYNAMIC_PROXY.md">the GraalVM documentation</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="logging-with-native-image"><a class="anchor" href="#logging-with-native-image"></a>Logging with Native Image</h3>
<div class="paragraph">
<p>If you are using dependencies that require logging components such as Apache Commons Logging or Log4j and are experiencing a <code>ClassNotFoundException</code> when building the native executable, you can resolve this by excluding the logging library and adding the corresponding JBoss Logging adapter.</p>
</div>
<div class="paragraph">
<p>For more details please refer to the <a href="logging#logging-adapters">Logging guide</a>.</p>
</div>
</div>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
